home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / gdb-4.12 / sim / sh / run.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  2.4 KB  |  122 lines

  1. /* run front end support for H8/500
  2.    Copyright (C) 1987, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of H8300 SIM
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* Steve Chamberlain
  22.    sac@cygnus.com */
  23.  
  24. #include <stdio.h>
  25. #include "bfd.h"
  26. #include "sysdep.h"
  27.  
  28. int
  29. main (ac, av)
  30.      int ac;
  31.      char **av;
  32. {
  33.   bfd *abfd;
  34.   bfd_vma start_address;
  35.   asection *s;
  36.   int i;
  37.   int verbose = 0;
  38.   int trace = 0;
  39.   char *name = "";
  40.   
  41.   for (i = 1; i < ac; i++)
  42.     {
  43.       if (strcmp (av[i], "-v") == 0)
  44.     {
  45.       verbose = 1;
  46.     }
  47.       else if (strcmp (av[i], "-t") == 0)
  48.     {
  49.       trace = 1;
  50.     }
  51.       else if (strcmp (av[i], "-p") == 0)
  52.     {
  53.       sim_set_profile(atoi(av[i+1]));
  54.       i++;
  55.     }
  56.       else if (strcmp (av[i], "-s") == 0)
  57.     {
  58.       sim_set_profile_size(atoi(av[i+1]));
  59.       i++;
  60.     }
  61.       else if (strcmp (av[i], "-m") == 0)
  62.     {
  63.       sim_size(atoi(av[i+1]));
  64.       i++;
  65.     }
  66.       else
  67.     {
  68.       name = av[i];
  69.     }
  70.     }
  71.   if (verbose)
  72.     {
  73.       printf ("run %s\n", name);
  74.     }
  75.   abfd = bfd_openr (name, "coff-sh");
  76.   if (abfd)
  77.     {
  78.  
  79.       if (bfd_check_format (abfd, bfd_object))
  80.     {
  81.  
  82.       for (s = abfd->sections; s; s = s->next)
  83.         {
  84.           unsigned char *buffer = malloc (bfd_section_size (abfd, s));
  85.           bfd_get_section_contents (abfd,
  86.                     s,
  87.                     buffer,
  88.                     0,
  89.                     bfd_section_size (abfd, s));
  90.           sim_write (s->vma, buffer, bfd_section_size (abfd, s));
  91.         }
  92.  
  93.       start_address = bfd_get_start_address (abfd);
  94.       sim_set_pc (start_address);
  95.       if (trace)
  96.         {
  97.           int done = 0;
  98.           while (!done)
  99.         {
  100.           done = sim_trace ();
  101.         }
  102.         }
  103.       else
  104.         {
  105.           sim_resume (0, 0);
  106.         }
  107.       if (verbose)
  108.         sim_info (printf, 0);
  109.  
  110.       /* Find out what was in r0 and return that */
  111.       {
  112.         unsigned char b[4];
  113.         sim_fetch_register(0, b);
  114.         return b[3];
  115.       }
  116.       
  117.     }
  118.     }
  119.  
  120.   return 1;
  121. }
  122.